from socket import *
from time import ctime

COD = "utf-8"
HOST = "127.0.0.1"
# 端口号
PORT = 21566
BUFSIZE = 1024
ADDR = (HOST, PORT)
# 创建socket对象
tcpCliSock = socket(AF_INET, SOCK_STREAM)
# 连接服务器
tcpCliSock.connect(ADDR)
while True:
    data = input(">> ").strip()
    # if not data:
    #     data = input(">> ").strip()
    if data == 'exit()':
        break
    # 发送消息
    if data != '':
        tcpCliSock.send(data.encode(COD))
        # 读取消息
        data = tcpCliSock.recv(BUFSIZE)
        if not data:
            break
        print("服务端响应：", data.decode(COD))
    else:
        continue

# 关闭客户端
tcpCliSock.close()
